﻿using QFramework;
using UnityEngine;

namespace ProjectSurvivor
{
    public class  Dissovle:MonoBehaviour
    {
        public Material Material;
        public static readonly int Color=Shader.PropertyToID("_Color");
        public static readonly int Fade=Shader.PropertyToID("_Fade");
        public Color DissovleColor;

        private void Start()
        {
            var material = Instantiate(Material);
            GetComponent<SpriteRenderer>().material = material;	
				
            material.SetColor(Color,DissovleColor);
            ActionKit.Lerp(1, 0, 0.5f, (fada) =>
                {
                    material.SetFloat(Fade,fada);
                    this.LocalScale(1 + (1 - fada) * 0.5f);
                })
                .Start(this, () =>
                {
                    Destroy(material);
                    this.DestroyGameObjGracefully();
                });
        }
    }
}